package com.edgar.nio.buffer;

import java.nio.ByteBuffer;

/**
 * @Auther EdgarLQS
 * @Date 2021-01-02 23:21
 */
public class NIOByteBufferPutGet {

    public static void main(String[] args) {

        //创建一个Buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);
        //类型化方式放入数据
        buffer.putInt(100);
        buffer.putLong(9);
        buffer.putChar('尚');
        buffer.putShort((short) 4);
        //取出
        buffer.flip();
        //         如果取得类型出问题的话会报错 java.nio.BufferUnderflowException
        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
//        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());
    }

}
